#!/usr/bin/env python

#            M2
#				_____
#          /     \
#         /       \
#         \_______/
#       M1         M3
#
#	The wheels are arranged in a circle around the robot chasis
#	Rotation in the clockwise direction (as depicted in the diagram above) 
#		is represented by a positive number
#	Rotation in the counter-clockwise (as depicted in the diagram above)  
#		is represented by a negative number


import socket
import sys

#Global Variables
int m1
int m2
int m3
int angle
size = 1024

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

def alert(msg):
	print >>sys.stderr, msg
	sys.exit(1)

def fulfwd():
	m1 = 100
	m2 = 0
	m3 = -100

def stp():
	m1 = 0
	m2 = 0
	m3 = 0

def wButton():
	if (m1 <= 100):
		m1 += 5
	if (m3 >= -100):
		m3 -= 5

def sButton():
	if (m1 >= -100):
		m1 -= 5
	if (m3 <= 100):
		m3 += 5

def eButton():
	if (m1 >= -100):
		m1 -= 5
	if (m2 <= 100):
		m2 += 5

def qButton():
	if (m1 <= 100):
		m1 += 5
	if (m2 >= -100):
		m2 -= 5

def cButton():
	if (m1 >= -100:
		m1 -= 5
	if (m2 <= 100):
		m2 += 5

def zButton():
	if (m2 >= -100):
		m2 -= 5
	if (m3 <= 100):
		m3 += 5

def dButtom():
	
def connectSvr():
	host = raw_input('\nPlease enter the host address: ')
	port = 50000
#	size = 1024

	try:
		s.connect((host,port))
		print '\nConnecting to server...\n'
	except Exception, e:
		alert('Something is wrong with %s:%d. Exception type is %s' % (host, port, e))
	print 'Connection Established!\n'

def txBender(tdata):
	print 'Sending: %s\n' % (tdata)
	s.send(tdata)
	rdata = s.recv(size)
	if (rdata == 's1'):
		print 'Wall detected on sensor 1'
	elif (rdata == 's2'):
		print 'Wall detected on sensor 2'
	elif (rdata == 's3'):
		print 'Wall detected on sensor 3'
	print '\nReceiving: %s\n' % (rdata) 
		

running = 1

connectSvr()
while running:
	choice = raw_input('What would you like to do?\n1. Send Data\n2. Exit\n')
	if choice == '2':
		running = 0	
	else:
		tdata = raw_input('\nEnter data to send to the robot:\n')
		txBender(tdata)

s.send('stop')
s.close()
exit()
